/*
 * @author: Sawyer(870756077@qq.com)
 * @date: 2017-10-24 11:12:53
 */

import * as types from './mutation-types'
import Vue from 'vue'
import Vuex from 'vuex'
// adminShell
import adminShell from './modules/admin-shell'
import goods from './modules/goods'
// pictureModal 图片库
import pictureModal from './modules/picture-modal'
// viusal 可视化
import viusal from './modules/viusal'

Vue.use(Vuex)
const debug = process.env.NODE_ENV !== 'production'
let state = {
    /**
     * 是否需要页面切换动画功能
     *
     * @type {boolean}
     */
    needPageTransition: false,
    /**
     * 页面切换效果时的名称
     *
     * @type {string}
     */
    pageTransitionName: '',
    /**
     * 上个页面 scroll 的信息
     *
     * @type {Object}
     */
    historyPageScrollTop: {},
    /**
     * 是否显示modal
     */
    modal: {
        bPictureModal: false
    }
}
let actions = {
    /**
     * 保存页面 scroll 高度
     *
     * @param {} commit
     * @param {string} path - 路由 path
     * @param {Number} scrollTop
     */
    saveScrollTop({ commit }, { path, scrollTop }) {
        commit(types.SAVE_SCROLL_TOP, { path, scrollTop })
    },
    /**
     * 显示或隐藏modal
     *
     * @param {Objßect} obj - bShow,modalKey
     */
    isModal({ commit }, obj) {
        commit(types.IS_MODAL, obj)
    }
}
let mutations = {
    [types.SAVE_SCROLL_TOP](state, { path, scrollTop }) {
        state.historyPageScrollTop[path] = scrollTop
    },
    /**
     * 显示或隐藏modal
     *
     * @param {*} state
     * @param {Boolean} bShow - 显示或隐藏modal
     * @param {String} modalKey
     * @param {Number} limit - 限制的个数 null 无限制
     * @param {Object} changInfo - 当前需要修改图片的信息
     */
    [types.IS_MODAL](state, { bShow, modalKey, limit, changeInfo }) {
        if (bShow) {
            state.modal[modalKey] = bShow
            state.pictureModal.limit = limit
            state.pictureModal.changeInfo = changeInfo
        } else {
            state.modal[modalKey] = bShow
        }
    }
}
export default new Vuex.Store({
    state,
    actions,
    mutations,
    modules: {
        namespaced: true,
        adminShell,
        goods,
        pictureModal,
        viusal
    },
    strict: debug
    // plugins: debug ? [createLogger()] : []
})
